#!/bin/bash

# This script will install libraryreminder on a server.
# Assuming the server runs Debian or derived distributions.
# Normally it will be executed only once.
# This script must be executed as root.

USERNAME=libraryreminder
USERDIR=/home/$USERNAME
INST_DIR=`pwd`

# TODO
# Install Sun Java

# Install the necessary server software

apt-get --assume-yes install maven2 firefox xvfb

# Create user
adduser --disabled-password --gecos "" $USERNAME

# Copy the files
cp -a $INST_DIR ${USERDIR}/
chown -R ${USERNAME}:${USERNAME} ${USERDIR}/*

# Add cronjob
crontab -u $USERNAME crontab

# Set JAVA_HOME
echo 'export JAVA_HOME=/usr/lib/jvm/java-6-sun/jre' >> ${USERDIR}/.profile